<?php

class Image extends CI_Model
{
    var $product_id = '';
    var $thumbnail = 0;
    var $url = '';

    function __construct()
    {
        parent::__construct();
    }

    function get_last_ten_entries()
    {
        $query = $this->db->get('User', 10);
        return $query->result();
    }

    function save()
    {
        $id = $this->input->post('id');;
        if ($id>0){
            $this->db->update('image',array("url"=>'/public/home/img/product/'.$id.'.jpg'), array("id"=>$id));
            return $id;

        }
        $this->product_id = $this->input->post('product_id');
        $this->thumbnail = $this->input->post('thumbnail');
        $this->db->insert('Image', $this);
        $id =  $this->db->insert_id();
        echo $id.'     ';
        $this->url = '/public/home/img/product/'.$id.'.jpg';

        $this->db->update('image',$this, array("id"=>$id));
        return $id;
    }

    function remove($id){
        $this->db->delete('image', array('id'=>$id));
        return 1;
    }

    function update()
    {
        $this->product_id = $this->input->get('product_id');
        $this->db->update('Image', $this, array('id' => $this->input->post('id')));
    }

}